/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package locusts;

import java.awt.geom.Rectangle2D;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import locusts.common.behaviours.BehaviourList;
import locusts.common.behaviours.FlockAlignmentBehaviour;
import locusts.common.behaviours.FlockCohesionBehaviour;
import locusts.common.behaviours.FlockSeparationBehaviour;
import locusts.common.behaviours.WanderBehaviour;
import locusts.common.entities.Flock;
import locusts.lib.FrameCounter;

/**
 *
 * @author Hamish Morgan
 */
public class Game {


    FrameCounter frameCounter;

//    private int flockSize;
    static final Random RAND = new Random();
    public Flock flock;

    public Game(int flockSize) {
//        this.flockSize = flockSize;
        frameCounter = new FrameCounter("Game");


        flock = new Flock();
        flock.populate(100, new Rectangle2D.Double(100,100,400,400));


             final double maxDistance = 100d;
        final double minDistance = 0d;
        final double maxAngle = 0.7d * Math.PI;
        // the amount a vehicle will slow down per second
        // relative importance of each behaviour
        final double alignmentWeight = 8d;
        final double cohesionWeight = 1d;
        final double separationWeight = 8d;
        final double wanderWeight = 0d;

        BehaviourList behaviours = new BehaviourList.Max();
        behaviours.add(new FlockAlignmentBehaviour(alignmentWeight,
                flock,
                minDistance, maxDistance, maxAngle));
        behaviours.add(new FlockCohesionBehaviour(cohesionWeight,
                flock,
                minDistance, maxDistance, maxAngle));
        behaviours.add(new FlockSeparationBehaviour(separationWeight,
                flock,
                minDistance, maxDistance, maxAngle));
        behaviours.add(new WanderBehaviour(wanderWeight));


        flock.setBehaviour(behaviours);
        // update the flock at 60fps
        new Timer("Flock Model Update Timer").schedule(new TimerTask() {

            private long lastUpdateTime = System.currentTimeMillis();

            @Override
            public void run() {
                frameCounter.markFrame();
                long newTime = System.currentTimeMillis();
                double timeDiff = (newTime - lastUpdateTime) / 1000d;
                lastUpdateTime = newTime;
                flock.update(timeDiff //                        , bounds
                        );
            }
        }, 0, 1000 / 60);
    }

  
}
